package sort;

import common.Print;

import java.util.Arrays;

/**
 * 快速排序
 */
public class QuickSort {
    public static void main(String[] args) {
        int[] arr = {30, 40, 60, 10, 20, 50};
        quickSort(arr,0,arr.length-1);
        Print.printArr(arr);
    }

    public static void quickSort(int[] arr,int start,int end){
        if(start < end){
            int startd = arr[start];
            int low = start;
            int high = end;
            while (low < high) {
                while (low < high && arr[high] >= startd) {
                    high--;
                }
                arr[low] = arr[high];
                while (low < high && arr[low] <= startd) {
                    low++;
                }
                arr[high] = arr[low];
            }
            arr[low] = startd;
            quickSort(arr,start,low);
            quickSort(arr,low+1,end);
        }
    }


}

